
#include <iostream>
#include <string>
#include <vector>
#include <boost/thread/thread.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/make_shared.hpp>

using namespace std;


class tester
{
public:
    tester()
    {
        m_spData = boost::make_shared<int>();
    }
    ~tester() {}
public:
    boost::shared_ptr<int> m_spData; // 可能其它类型。
};

tester gObject;

void fun(void)
{
    int j=0;
    while(j<500)
    {
        boost::shared_ptr<int> tmp = gObject.m_spData;
        std::cout<< "use count :" << gObject.m_spData.use_count() << std::endl;
        std::cout<<"fun: "<<j<<std::endl;
        usleep(1000);
        j++;
    }

}

int main()
{
    std::cout<< "use count :" << gObject.m_spData.use_count() << std::endl;
    // 多线程。
    boost::thread t1(fun);
    boost::thread t2(fun);

    t1.join();
    t2.join();

    std::cout<< "thread returned"<<std::endl;
    std::cout<< "use count :" << gObject.m_spData.use_count() << std::endl;
    return 0;
}



